package cn.diandiandidi.demo;

import java.util.Locale;
import java.util.Vector;

import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class MainActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        prepareLocaleArray();
        
        ListView lv = (ListView)findViewById(R.id.localeListLv);
        lv.setAdapter(new LocaleAdapter());
    }
    
    
    
    class LocaleAdapter extends BaseAdapter {
    	
    	private LayoutInflater m_inflater;
    	
    	public LocaleAdapter() {
    		m_inflater = LayoutInflater.from(MainActivity.this);
    	}
    	
		public int getCount() {
			return localStrs.size();
		}

		public Object getItem(int position) {
			return position;
		}

		public long getItemId(int position) {
			return position;
		}

		public View getView(int position, View convertView, ViewGroup parent) {
			if(convertView==null) {
				convertView = m_inflater.inflate(R.layout.list_item, null);
			}
			
			TextView resultTv = (TextView)convertView.findViewById(R.id.resultTv);
			resultTv.setText(localStrs.get(position));
			
			TextView funcNameTv = (TextView)convertView.findViewById(R.id.functionNameTv);
			funcNameTv.setText(localNameStrs.get(position));
			return convertView;
		}    	
    }
    
    private Vector<String> localStrs = new Vector<String>();
	private Vector<String> localNameStrs = new Vector<String>();
	
    private void prepareLocaleArray() {
		localStrs.clear();
		localNameStrs.clear();
		
		Locale[] locals = Locale.getAvailableLocales();
		
		int i = 0;
		for( ; i < locals.length; ++i ) {
			localStrs.add(locals[i].getDisplayName());
			localNameStrs.add(Integer.toString(i) + " getDisplayName");
			
			localStrs.add(locals[i].getDisplayLanguage());
			localNameStrs.add(Integer.toString(i) + " getDisplayLanguage");
			
			localStrs.add(locals[i].getCountry());
			localNameStrs.add(Integer.toString(i) + " getCountry");
			
			localStrs.add(locals[i].getDisplayCountry());
			localNameStrs.add(Integer.toString(i) + " getDisplayCountry");
			
			localStrs.add(locals[i].getLanguage());
			localNameStrs.add(Integer.toString(i) + " getLanguage");
			
			localStrs.add(locals[i].getISO3Country());
			localNameStrs.add(Integer.toString(i) + " getISO3Country");
			
			localStrs.add(locals[i].getISO3Language());
			localNameStrs.add(Integer.toString(i) + " getISO3Language");
			
			localStrs.add(locals[i].getDisplayVariant());
			localNameStrs.add(Integer.toString(i) + " getDisplayVariant");
			
			localStrs.add(locals[i].getVariant());
			localNameStrs.add(Integer.toString(i) + " getVariant");								
		}		
	}
}